package class6;

import java.util.concurrent.CompletableFuture;

public class demo2 {
    public static void main(String[] args) {
        CompletableFuture<Integer>future1=CompletableFuture.supplyAsync(()->{
           int sum=0;
           for(int i=0;i<5;i++){
               sum+=i;
           }
            return sum;
        });
        CompletableFuture<Integer>future2=CompletableFuture.supplyAsync(()->{
            int sum=0;
            for(int i=5;i<7;i++){
                sum+=i;
            }
            return sum;
        });

        CompletableFuture<Integer>future=future1.thenCombine(future2,(a,b)->{
            return a+b;
        });
        System.out.println(future.join());


    }
}
